package com.example.votingsystem.repository;

import com.example.votingsystem.entity.VoteRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.time.LocalDateTime;
import java.util.List;

public interface VoteRecordRepository extends JpaRepository<VoteRecord, Long> {
    List<VoteRecord> findByUserId(Long userId);
    
    @Query("SELECT COUNT(v) > 0 FROM VoteRecord v WHERE v.userId = ?1 AND v.voteTopic.id = ?2 AND DATE(v.votedAt) = CURRENT_DATE")
    boolean hasUserVotedToday(Long userId, Long topicId);
    
    List<VoteRecord> findByUserIdAndVoteTopicId(Long userId, Long topicId);
}
